﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SurveillanceLib
{
    /// <summary>
    /// 工厂类
    /// </summary>
    public class DriverFactory
    {
        #region 变量

        private static readonly object lockobject = new object();
        private static DriverFactory factory = null;

        #endregion

        #region 静态属性

        public static DriverFactory Factory
        {
            get
            {
                lock (lockobject)
                {
                    if (factory == null)
                    {
                        factory = new DriverFactory();
                    }
                }
                return factory;
            }
        }

        #endregion

        #region 方法

        /// <summary>
        /// 创建设备实例
        /// </summary>
        /// <param name="driverType"></param>
        /// <returns></returns>
        public DriverBase CreateDriver(string driverType)
        {
            DriverBase driver = null;
            if (string.IsNullOrWhiteSpace(driverType))
                return driver;

            DriverTypeEnum outDriverType; // 转换成对应的设备类型
            if (Enum.TryParse<DriverTypeEnum>(driverType, true, out outDriverType))
            {
                switch (outDriverType)
                {
                    case DriverTypeEnum.DH: // 大华
                        driver = new DH_Driver();
                        break;
                    case DriverTypeEnum.HK: // 海康
                        driver = null;
                        break;


                    default:
                        break;
                }
            }

            return driver;
        }

        #endregion
    }
}
